import random
import cards

from abstract_player import AbstractPlayer
from math import sqrt

class ArtificialPlayer1(AbstractPlayer):
    def __init__(self, game, name, bluffing = 0):
        AbstractPlayer.__init__(self)
        
        self.game = game
        self.name = name
        self.bluffing = bluffing
    
    def do_move(self):        
        probability = 1 / (self.num_opponents() + 1) 
        power = self.get_hand_power()[0]
        
        #print("Hand: %s, power: %d" % (cards.card_names(self.hole_cards), power))
        
        if self.game.checkable(self.current_bet):
            if len(self.game.community_cards) == 0:
                # pre flop
                if random.random() < probability:
                    self.bet(self.game.pot)
                else:
                    self.check()
            else:
                # post flop
                if random.random() < self.bluffing:
                    self.bet(self.game.pot)
                elif power == 1:
                    # high card
                    self.check()
                else:
                    # pair or better
                    self.bet(self.game.pot)
        else:
            if len(self.game.community_cards) == 0:
                ratio = random.random() / self.pot_odds()
                
                # pre flop
                if ratio > 1.5:
                    self.raise_amount(max(self.game.min_raise(), self.game.pot))
                elif ratio > 1:
                    self.call()
                else:
                    self.fold()               
            else:
                # post flop
                if power == 1:
                    # high card
                    self.fold()
                elif power == 2:
                    # pair
                    self.call()
                else:
                    # better than pair
                    self.raise_amount(max(self.game.min_raise(), self.game.pot))
    
    def __str__(self):
        return self.name + " (a1)"